<template>
	<view>
		<video controls=""
			src="http://spa71hcxj.hn-bkt.clouddn.com/%E5%8D%B0%E8%B1%A1%E8%A5%BF%E5%AE%89%EF%BC%9A118%E4%B8%AA%E9%95%9C%E5%A4%B4%EF%BC%8C%E5%B8%A6%E4%BD%A0%E7%9C%8B%E9%81%8D%E8%A5%BF%E5%AE%89%E5%8D%81%E4%B8%89%E6%9C%9D%E5%8F%A4%E9%83%BD%E5%8F%8A%E6%9C%80%E7%BE%8E%E8%87%AA%E7%84%B6%E9%A3%8E%E5%85%89_%E9%AB%98%E6%B8%851080P%E5%9C%A8%E7%BA%BF%E8%A7%82%E7%9C%8B%E5%B9%B3%E5%8F%B0_%E8%85%BE%E8%AE%AF%E8%A7%86%E9%A2%91.mp4"
			style="width: 100%;" poster="/static/icons/xian.png"></video>
	</view>
	<view>
		<view class="item" v-for="(item, index) in seniclist" @tap="toDetails(item.objectId)">
			<view class="pic">
				<image style="width: 100%;" :src="item.img" mode=""></image>
			</view>
			<view class="msg">
				<view class="name">{{ item.name }}</view>
				<div>
					<image src="/static/icons/shoucang.png"  style="width: 30px;height:30px;" mode="aspectFit"></image>
				</div>
				<view class="intro">{{ item.intro }}</view>
				<view class="icon" @tap="toggleFavorite(item.objectId, item)">

				</view>
			</view>
		</view>
	</view>

</template>

<script setup>
	import {
		ref
	} from 'vue';
	import {
		onLoad
	} from '@dcloudio/uni-app';
	import {
		CONFIG
	} from '../../utils/config';

	const type = ref(1);
	const favoriteIds = ref([]); // 存储收藏的景点ID

	onLoad(() => {
		getSenic();
	});

	const seniclist = ref([]);

	async function getSenic() {
		let query = {
			"type": 1
		};
		let queryStr = JSON.stringify(query);
		console.log(query);
		console.log(queryStr);
		let res = await uni.$get(CONFIG.leanCloud_url + "/1.1/classes/SecicItem", {
			where: queryStr
		});
		console.log(res);
		if (res.statusCode == 200) {
			seniclist.value = res.data.results;
		}
		console.log(seniclist.value);
	}

	async function toggleFavorite(id, item) {
		if (favoriteIds.value.includes(id)) {
			// 如果已经收藏，则取消收藏
			favoriteIds.value = favoriteIds.value.filter((id) => id !== item.objectId);
			await uni.$delete(CONFIG.leanCloud_url + "/1.1/classes/Favorites", {
				where: {
					objectId: id
				}
			});
		} else {
			// 如果未收藏，则添加收藏
			favoriteIds.value.push(item.objectId);
			await uni.$post(CONFIG.leanCloud_url + "/1.1/classes/Favorites", {
				objectId: id
			});
		}
	}

	function toDetails(id) {
		uni.navigateTo({

			url: "/pages/playDetails/playDetails?id=" + id
		});
	}
</script>

<style>
	.icon {
		position: absolute;
		right: 10px;
		top: 10px;
	}
</style>